//
//  UILabel+Extension.swift
//  Weibo10
//
//  Created by Leon on 15/10/16.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

extension UILabel {
    
    ///  遍历构造函数
    ///
    ///  - parameter title:       title
    ///  - parameter color:       color
    ///  - parameter fontSize:    fontSize
    ///  - parameter screenInset: 设置文字内容的边距
    ///
    ///  - returns: 自定义UILabel
    convenience init(title: String, color: UIColor = UIColor.darkGrayColor(), fontSize: CGFloat = 14, screenInset: CGFloat = 0) {
        
        self.init()
        
        text = title
        // 界面设计避免纯黑色
        textColor = color
        font = UIFont.systemFontOfSize(fontSize)
        numberOfLines = 0
        
        if screenInset == 0 {
            
            textAlignment = NSTextAlignment.Center
        } else {
            
            preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * screenInset
            textAlignment = NSTextAlignment.Left
        }
        
        sizeToFit()
    }
}
